#!/bin/bash

# https://nginx.org/en/linux_packages.html#Ubuntu

sudo apt install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring

curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
    | sudo tee /etc/apt/preferences.d/99nginx

sudo apt update
sudo apt install nginx

# 如果出现配置问题见：
# Ubuntu 20.04 升级 nginx 1.18 到 1.20.1
# https://blog.deskangel.com/2021/05/27/upgrade-nginx-to-1-20-1/

# https://debian.pkgs.org/10/nginx-amd64/nginx_1.20.1-1~buster_amd64.deb.html